var $project = {
    token_name: 'token_name',
    token_value: 'token_value',
    init: function(){
    },
    getBase: function(){
        if(location.protocal){
           return location.protocal + location.hostname;
        }

        return location.hostname;
    },
    getToken: function(){
        return $('#' + this.token_value).val();
    },
    addToken: function($data, $isAjax){
        if($isAjax){
            $data.data.tut_token = this.getToken();
        }
        else{
            $data.tut_token = this.getToken();
        }

        return $data
    },
    ajax: function($option) {
        $.ajax($project.addToken($option, true));
    },
    post: function($url, $data, $func, $dataType){
//      $.post("test.php", { 'choices[]': ["Jon", "Susan"] });
        $.post($url, $project.addToken($data, false), $func, $dataType);
    },
    get: function($url, $data, $func, $dataType){
        $.get($url, $project.addToken($data, false), $func, $dataType);
    },
    siteUrl: function($link){
        if($link){
            return SITE_URL + '/' + $link;
        }

        return  SITE_URL;
    },
    baseUrl: function($link){
        if($link){
            return BASE_URL + $link;
        }

        return  BASE_URL;
    },
    appUrl: function($link){
        if($link){
            return APP_URL + '/' + $link;
        }

        return  APP_URL;
    },
    getCookie: function(name) {
        if (document.cookie.length > 0) {
            var start = document.cookie.indexOf(name + "=");
            if (start != -1) {
                start = start + name.length + 1;
                var end = document.cookie.indexOf(";", start);
                if (end == -1)
                    end = document.cookie.length;
                return unescape(document.cookie.substring(start, end));
            }
        }
        return null;
    },
    /**
     * Set cookie with value
     * 
     * @param {String} name
     * @Param {String} value
     * @param {Number} days
     * @returns {Object} Whl Object
     */
    setCookie: function(name, value, path, days) {
        days = (typeof days == 'undefined') ? 7 : days;
        path = path || '/';
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = '; expires=' + date.toGMTString();
        document.cookie = name + '=' + value + expires + '; path=' + path;
        return this;
    },
    /**
     * Set cookie with value
     * 
     * @param {String} name
     * @Param {String} value
     * @param {Number} days
     * @returns {Object} Whl Object
     */
    setCookie2: function(name, value, days) {
        days = (typeof days == 'undefined') ? 7 : days;
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
        document.cookie = name + "=" + value + expires + "; path=/";
        return this;
    },
    /**
     * Delete the cookie
     * 
     * @param {String} name
     * @returns {Object} Whl object
     */
    deleteCookie: function(name, path) {
        this.setCookie(name, '', path, -1);
        return this;
    },
    removeComment: function($code){
        return $code.replace(/^(<\!\-\-)|(\-\-\>)$/, '').replace('-->', '');
    }
};

Object.extend = function($des, $src) {
    for (var $key in $src) {
        $des[$key] = $src[$key];
    }
    return $des;
}

Object.extend(Object, {
    getClassName: function($object) {
        var objString = Object.prototype.toString.call($object);
        return objString.match(/^\[object\s(.*)\]$/)[1];
    },
    isString: function($object) {
        return (Object.getClassName($object) === 'String');
    },
    isNumber: function($object) {
        return (Object.getClassName($object) === 'Number');
    },
    isArray: function($object) {
        return (Object.getClassName($object) === 'Array');
    },
    isObject: function($object) {
        return (Object.getClassName($object) === 'Object');
    },
    isUndefined: function($object) {
        return (typeof $object === 'undefined');
    },
    getKey: function($object) {
        var $key = [];
        for (var $item in $object) {
            $key.push($item);
        }
        return $key;
    },
    getValues: function($object) {
        var $value = [];
        for (var $item in $object) {
            $value.push($object[$item]);
        }
        return $value;
    }
});


Object.extend(String.prototype, {
    trim: function() {
        return this.replace(/^\s+|\s+$/, '');
    }
});

/*function Product(name, price) {
 this.name = name;
 this.price = price;
 
 if (price < 0)
 throw RangeError('Cannot create product "' + name + '" with a negative price');
 return this;
 }
 
 function Food(name, price) {
 Product.call(this, name, price);
 this.category = 'food';
 }
 Food.prototype = new Product();
 
 function Toy(name, price) {
 Product.call(this, name, price);
 this.category = 'toy';
 }
 Toy.prototype = new Product();
 
 var cheese = new Food('feta', 5);
 var fun = new Toy('robot', 4);
 
 alert(fun.name + ', ' + fun.category);
 */